package com.yh.csx.crm.service;

import com.alibaba.dubbo.config.annotation.Reference;
import com.yh.b2b.common.exception.CommonException;
import com.yh.b2b.common.response.CommonResultResponse;
import com.yh.b2b.messagecenter.facade.MessageFacade;
import com.yh.b2b.messagecenter.facade.enums.MessageType;
import com.yh.csx.crm.core.enums.BizError;
import com.yh.csx.crm.core.exception.BusinessException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * SMSService class
 *
 * @author huyalin
 * @date 2019/4/22
 */
@Slf4j
@Service
public class MessageService {

    @Reference
    private MessageFacade messageFacade;


    public void sendMessage(String code, List<String> telephones, String... tempParams) {
        CommonResultResponse result = null;
        try {
            result = messageFacade.sendMessage(MessageType.SMS, code, telephones, tempParams);
            if (log.isDebugEnabled()) {
                log.debug("发送短信到：" + telephones + "，参数为：" + Arrays.toString(tempParams));
                log.debug("短信中心返回结果：" + result.getMessage());
            }
        } catch (Exception e) {
            log.error("发送短信消息失败", e);
        }
        if (BizError.SUCCESS.getCode() != result.getCode()) {
            log.error("发送短信消息失败, 短信中心返回消息：", result.getMessage());
        }
    }
}
